<template>
    <div>
     <table>
        <tr>
            <td>机构名称</td>
            <td><input type="text" v-model="data.name" ></td>
        </tr>
        <tr>
            <td>封面图</td>
            <td>         <input type="file" @change="upload">
                <img style="height:50px;width: 50px;" :src="'https://localhost:7167'+data.img" alt="">
                </td>
        </tr>
        <tr>
            <td>特色服务</td>
            <td><select v-model="data.tSever">
                <option value="基础互联网使用培训">基础互联网使用培训</option>
                <option value="基础防诈骗培训">基础防诈骗培训</option>
                <option value="养生操">养生操</option>
                </select></td>
        </tr>
        <tr>
            <td>营业时间(单位:小时)</td>
            <td><input type="text" v-model="data.startTime" ></td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td><input type="text" v-model="data.address" ></td>
        </tr>
        <tr>
            <td>联系电话</td>
            <td><input type="text" v-model="data.phone" ></td>
        </tr>   
        <tr>
            <td></td>
            <td><input type="button" value="提交" @click="add"></td>
        </tr>
     </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';


const router = useRouter();
const upload=(e:any)=>{
    var f = e.target.files[0]
    var fd = new FormData();
    fd.append("file",f);

    axios.post("https://localhost:7167/api/UpLoad",fd).then(res=>{
        data.value.img = res.data;
    })

}
const add = () => {
    if(data.value.name == "" || data.value.startTime == "" || data.value.address == "" || data.value.phone == "" ){
        alert("请填写完整信息,不可有空缺数据");
        return;
    }
    axios.post("https://localhost:7167/api/SaveOld/AddSaveOld",data.value).then(res=>{
      if(res.data >0){
        alert("添加成功");
        router.push({path:'/ShowView'})
      }else{
        alert("添加失败");
      }
    })
}
const data = ref({
  "id": 0,
  "name": "",
  "img": "",
  "tSever": "",
  "startTime": '',
  "address": "",
  "phone": "",
  "faBu": false,
  "isDelete": true
})




</script>

<style scoped>

</style>